﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;

namespace GPCSC.Web.sjs
{
    public partial class jjwtgl : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_buildGrid();
            }
        }
        protected void f_buildGrid()
        {

            Hashtable htable = new Hashtable();
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            htable.Add("@CL_POSTID_PK", users.CL_POSTID_PK.ToString());
            DataSet ds = new DataReturn().ReturnData(htable, "selwtbypostid");

            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (dr["juvalue"].ToString() == "0")
                        {
                            dr["zt"] = "未解决";
                        }
                        else
                        {
                            dr["zt"] = "已解决";
                        }

                        if (dr["jutext"].ToString() == "1")
                        {
                            dr["jutext"] = "关于农村";

                        }
                        else if (dr["jutext"].ToString() == "2")
                        {
                            dr["jutext"] = "关于社区";
                        }
                        else if (dr["jutext"].ToString() == "3")
                        {
                            dr["jutext"] = "关于企业";
                        }
                        else
                        {
                            dr["jutext"] = "未选择";
                        }

                        dr["tjdate"] = Usual.f_convertDateTime(dr["tjdate"]).Date;
                    }
                }

                PostListS.DataSource = ds;
                PostListS.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

            }
        }
        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            try
            {
                string type = e.Parameters[0].ToString();
                if (type == "jj")
                {
                    string ids = e.Parameters[1].ToString();

                    Hashtable htable = new Hashtable();
                    htable.Add("juvalue", "1");
                    htable.Add("jjdate", DateTime.Now.ToString());
                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    dtable.databyhtables(htable, "update", "wts_table", "hdwt_id", ids);
                    f_buildGrid();
                }
                if (type == "2")
                {
                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    Hashtable htable = new Hashtable();
                    string like = e.Parameters[2].ToString().Trim();

                    like = "%" + like + "%";

                    htable.Add("@lgid", users.CL_USER_SOID.ToString());
                    htable.Add("@gj", like);

                    DataSet ds = new DataSet();
                    ds = new SqlReadXml().ReaderDataSet("sel_wt_bylikes", htable);

                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                if (dr["juvalue"].ToString() == "0")
                                {
                                    dr["zt"] = "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  checked=\"checked\" />未解决" + "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  onclick=\"jjes(this)\"  />已解决"; ;
                                }
                                else
                                {
                                    dr["zt"] = "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  checked=\"checked\" />已解决";
                                }

                                if (dr["jutext"].ToString() == "1")
                                {
                                    dr["jutext"] = "关于农村";

                                }
                                else if (dr["jutext"].ToString() == "2")
                                {
                                    dr["jutext"] = "关于社区";
                                }
                                else if (dr["jutext"].ToString() == "3")
                                {
                                    dr["jutext"] = "关于企业";
                                }
                                else
                                {
                                    dr["jutext"] = "未选择";
                                }

                                dr["tjdate"] = Usual.f_convertDateTime(dr["tjdate"]).Date;
                            }
                        }

                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);
                    }

                }
                if (type == "sel")
                {
                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    string types = e.Parameters[1].ToString().Trim();
                    string gj = e.Parameters[2].ToString().Trim();
                    string kdate = e.Parameters[3].ToString().Trim();
                    string jdate = e.Parameters[4].ToString().Trim();
                    string sql = "";
                    //select a.*,''zt  from (select * from wts_table where wtvalue like @gj  or wttex like @gj) a where 

                    //a.lgid = @lgid and a.isfor = 0 and a.jutext = @types and a.tjdate > @kdate and a.tjdate<@jdate  order by a.tjdate  desc
                    if (gj != "" && gj != null)
                    {
                        sql += "select a.*,''zt  from (select * from wts_table where wtvalue like '%" + gj + "%'  or wttex like '%" + gj + "%') a";
                    }
                    else
                    {
                        sql += "select a.*,''zt  from wts_table a";
                    }
                    sql += " where 1=1 ";
                    if (kdate != "" && kdate != null)
                    {
                        sql += " and a.tjdate>cast('" + kdate + "' as datetime)";
                    }
                    if (jdate != "" && jdate != null)
                    {
                        sql += " and a.tjdate<cast('" + jdate + "' as datetime)";
                    }
                    if (types != "" && types != null && types != "null")
                    {
                        sql += " and a.jutext ='" + types + "'";
                    }
                    sql += " and a.lgid ='" + users.CL_USER_SOID.ToString() + "'";
                    sql += " and a.isfor = 0";
                    sql += " order by a.tjdate  desc";
                    DataSet ds = new DataSet();
                    ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                if (dr["juvalue"].ToString() == "0")
                                {
                                    dr["zt"] = "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  checked=\"checked\" />未解决" + "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  onclick=\"jjes(this)\"  />已解决"; ;
                                }
                                else
                                {
                                    dr["zt"] = "<input type=\"radio\" name =\"" + dr["hdwt_id"].ToString() + "\"  checked=\"checked\" />已解决";
                                }

                                if (dr["jutext"].ToString() == "1")
                                {
                                    dr["jutext"] = "关于农村";

                                }
                                else if (dr["jutext"].ToString() == "2")
                                {
                                    dr["jutext"] = "关于社区";
                                }
                                else if (dr["jutext"].ToString() == "3")
                                {
                                    dr["jutext"] = "关于企业";
                                }

                                dr["tjdate"] = Usual.f_convertDateTime(dr["tjdate"]).Date;
                            }
                        }

                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);


                    }
                }

                if (type == "del")
                {
                    string ids = e.Parameters[1].ToString();
                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    Hashtable htab = new Hashtable();
                    htab.Add("isfor","1");
                    dtable.databyhtables(htab, "update", "wts_table", "hdwt_id", ids);
                    f_buildGrid();
                }

            }
            catch (Exception ee)
            {
                throw ee;
            }
            finally
            {
                LPanel.RenderControl(e.Output);
            }
        }
    }
}